package h0706;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description CPU算力分配
 * @date 2024/7/6 10:56
 */
public class CPUComputingPowerAllocating {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        //思路：根据以下算式。
        //sumA-a+b=sumB+a-b;
        //sumA-sumB=2(a-b);
        //a-b=(sumA-sumB)/2;

        //可能有多组测试数据
        while (sc.hasNext()){
            int numA = sc.nextInt();
            int numB = sc.nextInt();
            sc.nextLine();
            //输入A，B组的cpu算力
            ArrayList<Integer> A = new ArrayList<>();
            for (int i = 0; i < numA; i++) {
                A.add(sc.nextInt());
            }
            ArrayList<Integer> B=new ArrayList<>();
            for (int i = 0; i < numB; i++) {
                B.add(sc.nextInt());
            }
            int sumA=A.stream().mapToInt(Integer::intValue).sum();
            int sumB=B.stream().mapToInt(Integer::intValue).sum();

            int half_diff=(sumA-sumB)/2;
            //记录用于校验的最小的a
            int minA=Integer.MAX_VALUE;
            String ans="";
            for (Integer a : A) {
                if (B.contains(a-half_diff)){
                    if (a<minA){
                        minA=a;
                        ans=a+" "+(a-half_diff);
                    }
                }
            }
            System.out.println(ans);
        }


    }
}
